﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SerializationHelper
{
    public class SerColV2Operate : SerTool, ISerColV2Helper
    {


        #region ISerializationCollectionV2Helper 成员
        private void CheckPathIsNullOrEmpty(string path)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");
        }
        private void InitSerializationPath(string path)
        {
            CheckPathIsNullOrEmpty(path);
            _path = path;
        }
        public void SerializationCollection<T>(string path, IList<T> collection, SerColType type)
        {
            InitSerializationPath(path);
            switch (type)
            {
                case SerColType.Binary:
                    SerializationCollectionToBinary<T>(collection);
                    break;
                case SerColType.XML:
                    SerializationCollectionToXML<T>(collection);
                    break;
            }
        }

        public IList<T> DeSerializationCollection<T>(string path, SerColType type) where T : class
        {
            InitSerializationPath(path);
            IList<T> _collection = null;
            switch (type)
            {
                case SerColType.Binary:
                    _collection = DeSerializationBinaryToCollection<T>();
                    break;
                case SerColType.XML:
                    _collection = DeSerializationXMLToCollection<T>();
                    break;
            }
            return _collection;
        }

        #endregion
    }
}
